package com.atguigu.lease.web.admin.schedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @ClassName LeaseSchedule
 * @Author heartFade
 * @Date 2025-05-05 10:52
 * @Version 1.0
 * @Description TODO
 **/
@Component
public class LeaseSchedule {
    @Autowired
    LeaseAgreementService leaseAgreementService;
    @Scheduled(cron="0 0 0 * * *" )
    public void leaseSchedule(){

        System.out.println("执行定时任务");
        leaseAgreementService.update(new LambdaUpdateWrapper<LeaseAgreement>().in(LeaseAgreement::getStatus,
                LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING,LeaseStatus.RENEWING).gt(LeaseAgreement::getLeaseEndDate,new Date())
                .set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED));
    }
}
